<?php
/**
 * Created by PhpStorm.
 * User: jacob
 * Date: 18-10-12
 * Time: 下午4:38
 */
namespace Common;

use DB\Token;

abstract class PlutoApi extends JsonApi{
  protected function before(Request $request, Response $response): bool {
    if (!parent::before($request, $response)) return false;
    //token验证
    /**
     * @var $data RequestApi
     */
    $data = $request->data;
    $token = new Token();
    $uid = $token->get($data->token);
    if ($uid == null){
      $response->httpStatus = HttpStatus::Forbidden;
      $response->httpMessage = "token is error or is expire";
      return false;
    }
    $request->uid = $uid;
    return true;
  }
}